package com.baosight.sczx.zm.ce.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.basetools.TablePk;
import com.baosight.sczx.zm.ce.domain.ZMCELubricationStandard;

/**
 * 润滑标准
 * <p>Title: ServiceZMCEB3.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 张志芳
 * @version 1.0
 * <pre>Histroy:
 *          2011-12-19 下午04:31:34  张志芳  Create
 *</pre>
 */
public class ServiceZMCEB3 extends ServiceEPBase {
	/**
	 * 初始化方法
	 * <p>Function: initLoad</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCELubricationStandard</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-4-8上午09:57:14 张志芳
	 * </p>
	 *
	 */
	public EiInfo initLoad(EiInfo inInfo) {
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
		EiInfo outInfo = this.query(inInfo);		
		return outInfo;
	}

	/**
	 * 设备查询
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCELubricationStandard</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-26下午04:23:36 张志芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo query(EiInfo inInfo) {
		String fdEquipmentId = inInfo.getString("fdEquipmentId");
		StaticTools.setQueryParameters(inInfo, "fdEquipmentId", fdEquipmentId, true);//添加查询条件
		String fdStandardsForm = inInfo.getString("fdStandardsForm");
		StaticTools.setQueryParameters(inInfo, "fdStandardsForm", fdStandardsForm, true);//添加查询条件
		EiInfo outInfo = super.query(inInfo, "ZMCELubricationStandard.query", new ZMCELubricationStandard());

		return outInfo;
	}
	
	/**
	 * 设备新增
	 * <p>Function: insert</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCELubricationStandard</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-26下午04:23:46 张志芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo insert(EiInfo inInfo) {
		inInfo.getBlock("result").setCell(0, "fdKeyId", TablePk.getInstance().getNextValue("T_CE_LUBRICATIONSTANDARD"));//主键
		EiInfo outinfo = super.insert(inInfo, "ZMCELubricationStandard.insert", "result");
		return outinfo;

	}
	
	/**
	 * 设备修改
	 * <p>Function: update</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCELubricationStandard</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-26下午04:23:56 张志芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo update(EiInfo inInfo) {
		EiInfo outInfo = super.update(inInfo, "ZMCELubricationStandard.update");
		return outInfo;
	}

	/**
	 * 设备删除
	 * <p>Function: delete</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCELubricationStandard</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-26下午04:24:03 张志芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo delete(EiInfo inInfo) {
		EiInfo _temp = super.delete(inInfo, "ZMCELubricationStandard.delete");
		EiInfo outInfo = query(inInfo);
	    outInfo.setMsg(_temp.getMsg());
	    outInfo.setDetailMsg(_temp.getDetailMsg());
		
		return outInfo;
	}

	

	
//	/**
//	 * 校验重复
//	 * <p>Function: validate</p>
//	 * <p>Description: </p>
//	 * <p>return value:boolean</p>
//	 * <p>throws Exception:</p>
//	 * <p>History:
//	 *    2011-1-26下午04:26:16 张志芳
//	 * </p>
//	 *
//	 */
//	@SuppressWarnings("rawtypes")
//	private boolean validate(EiInfo inInfo, String sqlName, Map<String, String> params) {
//		if(params == null) {
//			params = new HashMap<String, String>();
//		}
//		String fdSerial = inInfo.getBlock("result").getCellStr(0, "fdSerial");
//		String fdPoint = inInfo.getBlock("result").getCellStr(0, "fdPoint");
//		
//		params.put("fdSerial", fdSerial);
//		params.put("fdPoint", fdPoint);
//		params.put("fdEquipmentId", inInfo.getBlock("result").getCellStr(0, "fdEquipmentId"));
//		
//		List result = dao.query(sqlName, params);
//		if(result!=null && result.size() > 0) {
//			inInfo.setStatus(-1);
//			if(result.size() > 1)
//			{
//				inInfo.setMsg("序号和润滑点都不能重复！");
//				return true;
//			}
//			ZMCELubricationStandard map = (ZMCELubricationStandard)result.get(0);
//			if(map.getFdSerial().toString().equals(fdSerial) && map.getFdPoint().toString().equals(fdPoint))
//			{
//				inInfo.setMsg("序号和润滑点都不能重复！");
//				return true;
//			}
//			if(map.getFdSerial().toString().equals(fdSerial))
//			{
//				inInfo.setMsg("序号不能重复！");
//				return true;
//			}
//			if(map.getFdPoint().toString().equals(fdPoint))
//			{
//				inInfo.setMsg("润滑点不能重复！");
//				return true;
//			}
//		}
//		return false;
//	}	
	
}

